/**
 * 
 */
package steffens.java.gui.defaultui.interactive.buttons.reflection;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;

import steffens.java.gui.defaultui.interactive.buttons.DefaultButton;
import steffens.java.gui.defaultui.interactive.events.buttons.ReflectionEvent;

/**
 * @author Steffen Baumann
 * @version 1.0 
 *
 */
public class ReflectionButton extends DefaultButton implements ActionListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ReflectionMethodCaller reflectionMethodCaller = null;
	private ReflectionEvent reflectionEvent = null;
	private static final String DEFAULT_REFLECTION_TEXT = "Reflection";
	/**
	 * 
	 */
	public ReflectionButton() {
		this(DEFAULT_REFLECTION_TEXT, DEFAULT_ICON, DEFAULT_SIZE, null, null);
	}
	public ReflectionButton(ReflectionMethodCaller reflectionMethodCaller, ReflectionEvent reflectionEvent){
		this(DEFAULT_REFLECTION_TEXT, DEFAULT_ICON, DEFAULT_SIZE, reflectionMethodCaller, reflectionEvent);
	}
	/**
	 * @param text
	 */
	public ReflectionButton(String text, ReflectionMethodCaller reflectionMethodCaller, ReflectionEvent reflectionEvent) {
		this(text, DEFAULT_ICON, DEFAULT_SIZE, reflectionMethodCaller, reflectionEvent);
	}

	/**
	 * @param icon
	 */
	public ReflectionButton(Icon icon, ReflectionMethodCaller reflectionMethodCaller, ReflectionEvent reflectionEvent) {
		this(DEFAULT_REFLECTION_TEXT, icon, DEFAULT_SIZE, reflectionMethodCaller, reflectionEvent);
	}

	/**
	 * @param size
	 */
	public ReflectionButton(Dimension size, ReflectionMethodCaller reflectionMethodCaller, ReflectionEvent reflectionEvent) {
		this(DEFAULT_REFLECTION_TEXT, DEFAULT_ICON, size, reflectionMethodCaller, reflectionEvent);
	}

	/**
	 * @param text
	 * @param icon
	 * @param size
	 */
	public ReflectionButton(String text, Icon icon, Dimension size, ReflectionMethodCaller reflectionMethodCaller, ReflectionEvent reflectionEvent) {
		super(text, icon, size);
		setCallerAndEvent(reflectionMethodCaller, reflectionEvent);
	}
	
	private void setCallerAndEvent(
			ReflectionMethodCaller reflectionMethodCaller,
			ReflectionEvent reflectionEvent) {
		setReflectionMethodCaller(reflectionMethodCaller);
		setReflectionEvent(reflectionEvent);
		this.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(this)){
			if(reflectionMethodCaller != null){
				if(reflectionEvent != null){
					reflectionMethodCaller.callMethod(reflectionEvent.getMethodName(), reflectionEvent.getMethodParameters());
				}
			}
			
		}
	}
	public void setReflectionEvent(ReflectionEvent reflectionEvent){
		this.reflectionEvent = reflectionEvent;
	}
	public ReflectionEvent getReflectionEvent(){
		return this.reflectionEvent;
	}
	public void setReflectionMethodCaller(ReflectionMethodCaller reflectionMethodCaller){
		this.reflectionMethodCaller = reflectionMethodCaller;
	}
	public ReflectionMethodCaller getReflectionMethodCaller(){
		return this.reflectionMethodCaller;
	}
}
